package com.zhongen.oa.datascope;

import com.zhongen.admin.api.dto.UserInfo;
import com.zhongen.common.core.constant.SecurityConstants;
import com.zhongen.common.core.datascope.UserDataScope;
import com.zhongen.common.security.service.UserInfoCoordinator;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RequiredArgsConstructor
public class CustomUserInfoCoordinator implements UserInfoCoordinator {

	private final DataScopeProcessor dataScopeProcessor;

	@Override
	public Map<String, Object> coordinateAttribute(UserInfo userInfo, Map<String, Object> attribute) {
		// 数据权限填充
		UserDataScope userDataScope = dataScopeProcessor.mergeScopeType(userInfo.getSysUser(), userInfo.getRoleList());
		attribute.put(SecurityConstants.USER_DATA_SCOPE, userDataScope);
		return attribute;
	}

}
